import {ElLoading, ElMessage} from "element-plus";

let showMessage = true;
export function showElMessage(showClose=true, message="成功", type='success'){
    if (showMessage){
        ElMessage({showClose: showClose, message: message, type: type});
    }
}

export function getLoadingObject(timeout=5000, closeAuto=false){
    // 初始化加载动画
    const loading = ElLoading.service({
        lock: true,
        text: 'Loading',
        background: 'rgba(0, 0, 0, 0.7)',
    });
    // 自动终止加载动画,默认为5秒
    if (closeAuto){
        setTimeout(() => {
            loading.close()
        }, timeout);
    }
    return loading;
}

export function formatTimeObj(t){
    const dateObject = new Date(t);
    const options = { timeZone: "Asia/Shanghai" };
    return dateObject.toLocaleString("en-US", options);
}
